package com.wjf.birdfish.util;

import java.io.IOException;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.*;
import org.apache.commons.httpclient.methods.GetMethod;
public class TestHttpClient {
	public HttpClient getClient()  {
		HttpClient client = new HttpClient();
          //def conf = Configuration.instance();
          // if ( conf.proxyOn )
          client.getHostConfiguration().setProxy("localhost", 9090);

            client.getParams().setAuthenticationPreemptive(true);
            Credentials defaultcreds = new UsernamePasswordCredentials("admin","111111");
            client.getState().setCredentials(AuthScope.ANY, defaultcreds);
            
            GetMethod method = new GetMethod("http://www.qq.com");
            int status=0;
			try {
				status = client.executeMethod(method);
			} catch (HttpException e) {
				 System.out.println("status="+status);
			} catch (IOException e) {
				 System.out.println("status="+status);
			}
            if(status != 200) {
               System.out.println("status="+status);// throw new Exception("could not get resource $url");
            }
        return client;
    }
	public static void main(String[] args) throws Exception{
		TestHttpClient client=new TestHttpClient();
		HttpClient hClient=client.getClient();
		System.out.println("client="+hClient.getHostConfiguration());
	}
}
